package com.rd.student.dashuju.wangbo.exercise02;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class SortTest implements Comparable, Comparator {

    private String name;
    private int age;
    private int score;

    @Override
    public String toString() {
        return "SortTest{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

    public static void main(String[] args) {
        ArrayList arrayList = new ArrayList();
        studentMothod(arrayList);

    }
    public static void studentMothod(ArrayList arrayList){
        SortTest sortTest1 = new SortTest("liusan",20,90);
        SortTest sortTest2 = new SortTest("lisi",22,90);
        SortTest sortTest3 = new SortTest("wangwu",20,99);
        SortTest sortTest4 = new SortTest("sunliu",22,100);
        arrayList.add(sortTest1);
        arrayList.add(sortTest2);
        arrayList.add(sortTest3);
        arrayList.add(sortTest4);
        for (Object obj : arrayList){
            System.out.println(obj);
        }
        Collections.sort(arrayList);
        System.out.println(arrayList);

    }

    public SortTest() {
    }


    public SortTest(String name, int age, int score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    @Override
    public int compareTo(Object o) {
        SortTest sortTest = (SortTest) o;
        if (this.score > sortTest.score) {
            return -1;
        } else if (this.score < sortTest.score) {
            return 1;
        } else {
            if (this.age > ((SortTest) o).age) {
                return 1;
            } else if (this.age < ((SortTest) o).age) {
                return -1;
            } else {
                return 0;

            }

        }

    }

    @Override
    public int compare(Object o1, Object o2) {
        return 0;
    }
}
